<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>通过拖拽分组的小例子</title>
    <style>
      body {
        display: flex;
        justify-content: space-around;
      }
      .box1,
      .box2 {
        padding: 10px;
        width: 300px;
        border: 1px solid #000;
        min-height: 50px;
      }
      .box2 {
        max-height: 500px;
      }
      .demo {
        list-style: none;
        background-color: aqua;
        margin: 10px;
        height: 30px;
        padding-left: 5px;
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <div>
      <h1>组一：知识列表</h1>
      <ul class="box1" id="box1Out">
        <li class="demo" draggable="true">1. HTML5+CSS3</li>
        <li class="demo" draggable="true">2. WEBPACK</li>
        <li class="demo" draggable="true">3. VUE</li>
        <li class="demo" draggable="true">4. React</li>
        <li class="demo" draggable="true">5. ES5/ES6</li>
      </ul>
    </div>
    <div>
      <h1>组二：你喜欢的</h1>
      <ul class="box2" id="boxFrame"></ul>
    </div>

    <script>
      //被拖的对象
      var demolist = document.querySelectorAll('.demo')
      // 当前正在拖的是哪个li
      var dragDom = null
      for (let i = 0, len = demolist.length; i < len; i++) {
        demolist[i].ondragstart = function (ev) {
          // console.log(this);
          // console.log(demolist[i]);
          dragDom = this
        }
      }

      //目标对象， 容器
      var boxFrame = document.getElementById('boxFrame')
      // dragover  drap

      boxFrame.ondragover = function (ev) {
        ev.preventDefault()
        console.log('在范围内拖动')
      }
      boxFrame.ondrop = function () {
        console.log(dragDom)
        this.appendChild(dragDom)
        //被拖拽的对象插入到目标容器
      }
    </script>
  </body>
</html>
